<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            position: absolute;
            left: 0;
            width: 200px;
            height: 200px;
            background-color: brown;
        }
    </style>
</head>
<body>
    <button>移动按钮</button>
    <div></div>
    <script>
        var div = document.querySelector('div');
        var button = document.querySelector('button');
        // div 移动
        button.addEventListener('click',() =>{
            div.style.left = 500 + 'px';
        });
        // div 通过定时器，一直往前走。
        setInterval(() =>{
            var currentleft = div.offsetLeft;
            div.style.left = currentleft + 50 + 'px';
        },1000);
    </script>

</body>
</html>